/*
 * @Author: huzhanglin 799490931@qq.com
 * @Date: 2023-12-24 19:07:49
 * @LastEditors: huzhanglin 799490931@qq.com
 * @LastEditTime: 2023-12-24 21:32:01
 * @FilePath: \my-app01\src\app\todo-list\todo-list.component.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import {
  CommonModule,
  CurrencyPipe,
  DatePipe,
  JsonPipe,
  SlicePipe,
  TitleCasePipe,
  UpperCasePipe,
} from '@angular/common';
import { Component } from '@angular/core';
import { RouterOutlet } from '@angular/router';
import { MyDirective01Directive } from '../my-directive-01.directive';
import { MyNgModelComponent } from '../my-ng-model/my-ng-model.component';
import { MyNgIfComponent } from '../my-ng-if/my-ng-if.component';
import { UserComponent } from '../user/user.component';
import { HttpClientModule } from '@angular/common/http';
import { FormsModule } from '@angular/forms';
import { Myc01Component } from '../myc01/myc01.component';
import { MyNgForComponent } from '../my-ng-for/my-ng-for.component';
import { LogService } from '../services/log-service.service';

@Component({
  selector: 'app-todo-list',
  standalone: true,
  imports: [
    CommonModule,
    FormsModule,
    RouterOutlet,
    Myc01Component,
    CurrencyPipe,
    DatePipe,
    JsonPipe,
    SlicePipe,
    TitleCasePipe,
    UpperCasePipe,
    HttpClientModule,
    UserComponent,
    MyNgForComponent,
    MyNgIfComponent,
    MyNgModelComponent,
    MyDirective01Directive,
  ],
  templateUrl: './todo-list.component.html',
  styleUrl: './todo-list.component.css',
})
export class TodoListComponent {
  todo = '';
  todoList = ['上课', '开会', '出差'];
  size: number = this.todoList.length;
  private logService: LogService;
  constructor(logService: LogService) {
    this.logService = logService;
  }

  doAdd() {
    this.logService.log('do add', 'doAdd');
    if (this.todo.length > 0) {
      this.todoList = this.todoList.concat(this.todo);
      this.todo = '';
    }
    this.size = this.todoList.length;
  }

  doDelete(index: number) {
    // console.log(index);
    this.todoList.splice(index, 1);
    this.size = this.todoList.length;
  }
}
